$(function () {
    var option={
        url:'../sys/role/list',
        pagination:true,//显示分页条
        sidePagination:'server',//服务器端分页
        showRefresh:true,//显示刷新按钮
        search:true,
        toolbar:'#toolbar',
        striped:true,//设置为true会有隔行变色效果
        columns:[
            {
                field:'roleId',
                title:'序号',
                width:40,
                formatter: function(value, row, index) {
                    var pageSize = $('#table').bootstrapTable('getOptions').pageSize;
                    var pageNumber = $('#table').bootstrapTable('getOptions').pageNumber;
                    return pageSize * (pageNumber - 1) + index + 1;
                }
            },

            {checkbox:true},
            { title: '角色ID', field: 'roleId'},
            { title: '角色名称', field: 'roleName' },
            { title: '备注 ', field: 'remark' },
            { title: '创建时间', field: 'createTime'}
        ]};
    $('#table').bootstrapTable(option);
});


var vm = new Vue({
    el:'#dtapp',
    data:{
        showList: true,
        title: null,
        role: {}
    },
    methods:{
        del: function(){
            doTask('roleId', '删除', 'role/del');
        },
        add: function(){
            vm.showList = false;
            vm.title = "新增";
            vm.role = {};
        },
        update: function () {
            var id = 'roleId';
            var roleId = getSelectedRow()[id];
            if(roleId == null){
                return ;
            }

            $.get("../sys/role/info/"+roleId, function(r){
                vm.showList = false;
                vm.title = "修改";
                vm.role = r.role;
            });
        },
        saveOrUpdate: function () {
            var url = vm.role.roleId == null ? "../sys/role/save" : "../sys/role/update";
            $.ajax({
                type: "POST",
                url: url,
                data: JSON.stringify(vm.role),
                success: function(r){
                    if(r.code === 0){
                        layer.alert('操作成功', function(index){
                            layer.close(index);
                            vm.reload();
                        });
                    }else{
                        layer.alert(r.msg);
                    }
                }
            });
        },
        reload: function (event) {
            vm.showList = true;
            $("#table").bootstrapTable('refresh');
        }
    }
});